package com.bobo.web.provider.util.commutils;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;

/**
 * Base64加解密
 *
 * @author:liuwenjun
 * @version:1.0
 * @date:2017/8/15
 */
public class Base64Encryptor {
    /**
     * 解密
     *
     * @param str
     * @returnn
     */
    public static String decodeBase64(String str) {
        if (StringUtils.isEmpty(str)) {
            return "";
        }
        Base64 base64 = new Base64();
        byte[] decodeBytes = base64.decodeBase64(str.getBytes());
        return new String(decodeBytes);
    }

    /**
     * 加密
     *
     * @param base64Str
     * @return
     */
    public static String encodeBase64(String base64Str) {
        if (StringUtils.isEmpty(base64Str)) {
            return "";
        }
        Base64 base64 = new Base64();
        byte[] encodeBytes = base64.encodeBase64Chunked(base64Str.getBytes());
        return new String(encodeBytes);
    }
}
